package com.dfrz.problem.action.staffmanage;
	
import org.apache.struts2.dispatcher.SessionMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dfrz.problem.model.Employee;
import com.dfrz.problem.model.Role;
import com.dfrz.problem.model.User;
import com.dfrz.problem.service.EmployeeService;
import com.dfrz.problem.service.GiveroleEmployeeService;
import com.dfrz.problem.service.RoleService;
import com.dfrz.problem.utils.Result;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class GiveroleEmployeeAction extends ActionSupport{
	private static final long serialVersionUID = 1L;
	private static final Logger logger = LoggerFactory.getLogger(GiveroleEmployeeAction.class);
	private GiveroleEmployeeService giveroleEmployeeService;
	private EmployeeService employeeService;
	private RoleService roleService;
	private User user;
	private Employee employee;
	private String employeeEmail;
	private int roleId;

	/**
	 * 赋予角色信息校验
	 */
	public String giveroleEmployee(){
		if(roleId == 0){
			addFieldError("role", "请选择角色");
			return INPUT;
		}
		Result<Employee> retEmployee = employeeService.getEmployee(employeeEmail);
		Role retRole = roleService.getRole(roleId);
		retEmployee.getResult().setRole(retRole);
		giveroleEmployeeService.giveroleEmployee(retEmployee.getResult());

		return SUCCESS;
	}
	
	public String giveroleInterface(){
		return SUCCESS;
	}

	public GiveroleEmployeeService getGiveroleEmployeeService() {
		return giveroleEmployeeService;
	}


	public void setGiveroleEmployeeService(
			GiveroleEmployeeService giveroleEmployeeService) {
		this.giveroleEmployeeService = giveroleEmployeeService;
	}

	public User getUser() {
		SessionMap<String, Object> session = (SessionMap<String, Object>)
				ActionContext.getContext().getSession();
		user = (User) session.get("user");
		return user;
	}


	public void setUser(User user) {
		this.user = user;
	}


	public Employee getEmployee() {
		return employee;
	}


	public void setEmployee(Employee employee) {
		this.employee = employee;
	}


	public static long getSerialversionuid() {
		return serialVersionUID;
	}


	public static Logger getLogger() {
		return logger;
	}
	
	public void setEmployeeEmail(String employeeEmail) {
		this.employeeEmail = employeeEmail;
	}
	
	public void setRoleId(int roleId) {
		this.roleId = roleId;
	}

	public void setEmployeeService(EmployeeService employeeService) {
		this.employeeService = employeeService;
	}
	
	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}
}
